import Component from './Component'
import {useState} from '../react-dom/index';


function createElement(type, config, children) {
  let ref;
  if(config){
      delete config.__source;
      delete config.__self;
      ref = config.ref;
  }
  let props = { ...config };
  if (arguments.length > 3) {
      children = Array.prototype.slice.call(arguments, 2);
  }
  props.children = children;
  return {
      type,
      props,
      ref
  };
}

function createRef() {
  return {
    current: null
  }
}

function createContext() {
  function Provider(props) {
    Provider._value = props.value;
    return props.children;
  }
  function Consumer(props) {
    return props.children(Provider._value);
  }
  return {
    Provider,
    Consumer
  }
}

const React = {
  createElement,
  Component,
  createRef,
  createContext,
  useState
};
export default React;